using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class ZB_QuestionsOptionsService : BaseAppService<ZB_QuestionsOptionsDto, ZB_QuestionsOptions , ZB_QuestionsOptionsRepository>
        {
        readonly ExcelHelp _excelHelp;
        public ZB_QuestionsOptionsService (ZB_QuestionsOptionsRepository repository,ExcelHelp excelHelp) : base(repository){
        _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<ZB_QuestionsOptions, ZB_QuestionsOptionsDto>
            GetLoadPageOffsetMode(PagingModel<ZB_QuestionsOptionsDto>
                pagingQueryModel)
                {
                var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
                var baseQuery = _repository.QueryBase().AsNoTracking();
                loadPageOffsetModel.QueryWhere = this.CreateQRList()

         .Add("ZBCourseQuestionsId","=") //
         .Add("option","=") //
         .Add("content","=") //
         .Add("IsAnswer","=") //
         .Add("CreateFactory","=") //
         .Add("CreateDept","=") //
         .Add("UpdateDept","=") ;//


                loadPageOffsetModel.BasqQuery = baseQuery;
                loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
                loadPageOffsetModel.Selector = model => new  ZB_QuestionsOptions() {
                Id = model.Id,
ZBCourseQuestionsId= model.ZBCourseQuestionsId,//
option= model.option,//
content= model.content,//
IsAnswer= model.IsAnswer,//
CreateFactory= model.CreateFactory,//
CreateDept= model.CreateDept,//
UpdateDept= model.UpdateDept,//
                };
                return loadPageOffsetModel;
                }


                public async Task <IPageModel<ZB_QuestionsOptionsDto>> GetList(PagingModel<ZB_QuestionsOptionsDto>
                    pagingQueryModel)
                    {
                    var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                    return await base.LoadPageOffsetAsync(loadPageOffsetModel);
                    }


                    public async Task<string>
                        Export(PagingModel<ZB_QuestionsOptionsDto>
                            pagingQueryModel)
                            {
                            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
                            var excelData = DataList.Select(model => new
                            {
model.ZBCourseQuestionsId,
ZBCourseQuestionsId_title ="",
model.option,
option_title ="",
model.content,
content_title ="",
model.IsAnswer,
IsAnswer_title ="",
model.CreateFactory,
CreateFactory_title ="",
model.CreateDept,
CreateDept_title ="",
model.UpdateDept,
UpdateDept_title ="",
                            }).ToList();




                            return _excelHelp.Create(excelData);
                            }

                            }

                            }
